home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-30 | 2.1 KB | 96 lines | [TEXT/MSET] |
- $16 mybuffer
-
- : $>selID ( addr len -- n )
- put: mybuffer
- uc: mybuffer
- get$: mybuffer
- sel? not ?error 124
- hash
- 0 -> dfrselID ;
-
- :class OBJ_ARRAY+ super{ OBJ_ARRAY } 32767 indexed
-
- :m selfinit: { \ dln slf -- }
- idxBase 6 - w@ -> dln self -> slf \ Set up
- limit 0
- ?DO
- slf I ^elem dln cmove
- LOOP ;m
-
- \ applySel: needs the addr len of a selector
- \ e.g. " release:" applySel: tobject
- \ this would apply release: to each object in the array
-
- :m applySel: { addr len \ selID slf -- } \ applies the given selector to each object
- addr len $>selID -> selID
- self -> slf
- limit 0
- ?DO
- i select: slf
- slf selid (bwith) EX-METHOD \ we could make this faster
- LOOP ;m
-
- \ applycfa: needs the cfa of a word that sends a late bound message to an
- \ object that will be on the stack
- \ e.g. : initRect { obj -- }
- \ 10 10 20 20 put: obj ;
- \ ' initRect applycfa: tobject
-
- :m applycfa: { cfa \ slf -- } \ applies the given cfa with each object selected as current
- self -> slf
- limit 0
- ?DO
- i select: slf
- slf cfa execute \ we could make this faster
- LOOP ;m
-
- ;class
-
- endload
-
- *** EXAMPLE USE
-
- :class var+ super{ var }
-
- :m classinit:
- 4 put: super ;m
-
- ;class
-
- :class test super{ var+ OBJ_ARRAY+ }
-
- :m classinit:
- classinit: super
- selfinit: super ;m
-
- ;class
-
- 3 test v
-
- " get:" applySel: v \ verify that selfinit: worked
-
- : put5 { obj -- }
- 5 put: obj ;
-
- ' put5 applycfa: v
-
- " get:" applySel: v \ verify that applycfa: worked
-
-
- *** DESCRIPTION
-
- Class obj_array is a great concept and works very well in most circumstances.
- The problem with obj_array is that it assumes all ivar data want to be
- initialized to values of zero. In otherwords, only the index 0 ivar will
- receive the classinit: message. All other indexed ivars are set to zero.
- Obj_array+ has a method, selfinit:, that assures all ivar data is properly
- initialized.
-
- Any subclass of obj_array+ should contain a classinit: method that calls classinit: super
- and selfinit: super as shown in the above example.
-
- We also have methods for applying either the same selector or the same xt (cfa) to
- every object in the array.
-
- *** REVISION HISTORY
-